#pragma once

#include <memory>

#include "helper/sqlite/AutoDBDecorator.h"

namespace helper {
namespace sqlite {

//move syntax ????
class AutoDB {
public:
  static AutoDB make_memory(const std::string & name = "") ;
  static AutoDB make_file(const std::string & name, const std::string & dir = ".") ;
  static AutoDB make_db(const std::string & url);

  AutoDB();
  AutoDB(AutoDB && other) ;
  AutoDB & operator =(AutoDB && other) ;

  AutoDB(const AutoDB &) = delete;
  AutoDB & operator =(const AutoDB &) = delete;

  ~AutoDB() ;

  inline IDB & ref() const{ 
    return *_db;
  }

  inline operator bool() const{
    return _db  && _decorator;
  }

protected:
  //pre-condition: assert(db != nullptr);
  AutoDB(std::unique_ptr<IDB> && db);

private:
  void __move(AutoDB && other);
  std::unique_ptr<IDB> _db;
  std::unique_ptr<AutoDBDecorator> _decorator;
};

}//namespace sqlite
}//namespace helper
